/*-------------------<-- Start of Description-->---------------------\ | Insert a paragraph (line) into the word documents; | |--------------------------------------------------------------------| |---------------------<-- End of Description-->----------------------| |------------<-- Start of Files or Arguments Needed-->---------------| | auguments: | | numoflines - how many lines you want to insert; default is 1; | | insidedata - inside a data step or not; default is F; | | F: outside the data step; | | T: inside the data step; | | wordref - the window reference; default is "wordsys"; | |-------------<-- End of Files or Arguments Needed-->----------------| |--------------------------------------------------------------------| |------------------<-- Start of Files Created-->---------------------| | Example: %insertparas(T,2)/%insertparas(T)/%insertparas(2)/ | | %insertparas(2, T); | | Usage: %insertparas(numofparas, insidedata, wordref); | \-------------------<-- End of Files Created-->---------------------*/ %macro insertparas/parmbuff; /*--------------------------------------------\ | Copy Right: Duo Zhou; | | Created: 2-23-2001 11:15pm; | | Modified: 12-25-2001 4:01am; | | Purpose: Insert the new paragraph (line); | \--------------------------------------------*/ %local _i_ _j_ numofparas wordref npars numoflines insidedata par parcount arg fref numsid wsid rc; %let parcount=1; %let par&parcount=%qscan(&syspbuff, &parcount, %str( (),)); %do %while(%length(&&par&parcount) gt 0); %let parcount=%eval(&parcount+1); %let par&parcount=%qscan(&syspbuff, &parcount, %str( (),)); %end; %let parcount =%eval(&parcount-1); %if (%index(%upcase(&par1), T)) %then %do; %let insidedata=%qscan(&syspbuff,1,%str( (),)); %if &parcount > 1 %then %do; %let numoflines=%qscan(&syspbuff,2,%str( (),)); %end; %else %do; %let numoflines=; %end; %end; %else %do; %let numoflines=%qscan(&syspbuff,1,%str( (),)); %if &parcount > 1 %then %do; %let insidedata=%qscan(&syspbuff,2,%str( (),)); %end; %else %do; %let insidedata=F; %end; %end; %if (%sysfunc(rxmatch(%sysfunc(rxparse($a)),&numoflines))) or (&numoflines eq) %then %do; %let numoflines=1; %end; /****/ %let arg=%qscan(&syspbuff,-1,%str((),)); %let fref=; %let wsid=0; %if (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WORDREF=))) or (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WINREF=))) or (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WINDOW=))) or (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WIN=))) %then %do; %let fref=%qscan(&arg, 2, %str(= )); %put --> Note: Checking the status of window "&fref" to see if it is open.; %end; %else %if (%sysfunc(rxmatch(%sysfunc(rxparse($a)),&arg))) and (%quote(%upcase(&arg)) ne %quote(T)) and (%quote(%upcase(&arg))ne %quote(TRUE)) %then %do; %if not (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(=))) %then %do; %let fref=%sysfunc(compress(&arg)); %put --> Note: Checking the status of window "&fref" to see if it is open.; %end; %else %do; %put --> Alert! Keyword Parameter isn%str(%')t declared!; %end; %end; %else %do; %let fref=wordsys; %put --> Note: No window reference is specified%str(;) Checking the status of the default; %put --> window "&fref" to see if it is open.; %end; /****/ %if (&fref ne ) %then %do; %let wsid=%sysfunc(fopen(&fref,o,132,e)); %end; %if &wsid %then %do; %let rc=%sysfunc(fclose(&wsid)); %if (%quote(%upcase(&insidedata))=%quote(T)) or(%quote(%upcase(&insidedata))=%quote(TRUE)) %then %do; file &fref lrecl=2000; %do _i_=1 %to &numoflines; put '[InsertPara]'; %end; %end; %else %do; data _null_; file &fref lrecl=2000; %do _i_=1 %to &numoflines; put '[InsertPara]'; %end; run; %end; %end; %else %do; %put ==> Alert! Incorrect window reference "&fref", or window "&fref" isn%str(%')t open.; %end; %mend insertparas;